<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Performance &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="Random sampling (numpy.random)" href="index.html" >
    <link rel="next" title="Cython API for random" href="c-api.html" >
    <link rel="prev" title="What’s New or Different" href="new-or-different.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../routines.html" >Routines</a></li>
          <li class="active"><a href="index.html" accesskey="U">Random sampling (<code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.random</span></code>)</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="c-api.html" title="Cython API for random"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="new-or-different.html" title="What’s New or Different"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Performance</a><ul>
<li><a class="reference internal" href="#recommendation">Recommendation</a></li>
<li><a class="reference internal" href="#timings">Timings</a></li>
<li><a class="reference internal" href="#performance-on-different-operating-systems">Performance on different Operating Systems</a><ul>
<li><a class="reference internal" href="#bit-linux">64-bit Linux</a></li>
<li><a class="reference internal" href="#bit-windows">64-bit Windows</a></li>
<li><a class="reference internal" href="#id1">32-bit Windows</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="new-or-different.html"
                        title="previous chapter">What’s New or Different</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="c-api.html"
                        title="next chapter">Cython API for random</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="performance">
<h1>Performance<a class="headerlink" href="#performance" title="Permalink to this headline">¶</a></h1>
<div class="section" id="recommendation">
<h2>Recommendation<a class="headerlink" href="#recommendation" title="Permalink to this headline">¶</a></h2>
<p>The recommended generator for general use is <a class="reference internal" href="bit_generators/pcg64.html#numpy.random.PCG64" title="numpy.random.PCG64"><code class="xref py py-obj docutils literal notranslate"><span class="pre">PCG64</span></code></a>. It is
statistically high quality, full-featured, and fast on most platforms, but
somewhat slow when compiled for 32-bit processes.</p>
<p><a class="reference internal" href="bit_generators/philox.html#numpy.random.Philox" title="numpy.random.Philox"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Philox</span></code></a> is fairly slow, but its statistical properties have
very high quality, and it is easy to get assuredly-independent stream by using
unique keys. If that is the style you wish to use for parallel streams, or you
are porting from another system that uses that style, then
<a class="reference internal" href="bit_generators/philox.html#numpy.random.Philox" title="numpy.random.Philox"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Philox</span></code></a> is your choice.</p>
<p><a class="reference internal" href="bit_generators/sfc64.html#numpy.random.SFC64" title="numpy.random.SFC64"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SFC64</span></code></a> is statistically high quality and very fast. However, it
lacks jumpability. If you are not using that capability and want lots of speed,
even on 32-bit processes, this is your choice.</p>
<p><a class="reference internal" href="bit_generators/mt19937.html#numpy.random.MT19937" title="numpy.random.MT19937"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MT19937</span></code></a> <a class="reference external" href="https://www.iro.umontreal.ca/~lecuyer/myftp/papers/testu01.pdf">fails some statistical tests</a> and is not especially
fast compared to modern PRNGs. For these reasons, we mostly do not recommend
using it on its own, only through the legacy <a class="reference internal" href="legacy.html#numpy.random.RandomState" title="numpy.random.RandomState"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RandomState</span></code></a> for
reproducing old results. That said, it has a very long history as a default in
many systems.</p>
</div>
<div class="section" id="timings">
<h2>Timings<a class="headerlink" href="#timings" title="Permalink to this headline">¶</a></h2>
<p>The timings below are the time in ns to produce 1 random value from a
specific distribution.  The original <a class="reference internal" href="bit_generators/mt19937.html#numpy.random.MT19937" title="numpy.random.MT19937"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MT19937</span></code></a> generator is
much slower since it requires 2 32-bit values to equal the output of the
faster generators.</p>
<p>Integer performance has a similar ordering.</p>
<p>The pattern is similar for other, more complex generators. The normal
performance of the legacy <a class="reference internal" href="legacy.html#numpy.random.RandomState" title="numpy.random.RandomState"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RandomState</span></code></a> generator is much
lower than the other since it uses the Box-Muller transformation rather
than the Ziggurat generator. The performance gap for Exponentials is also
large due to the cost of computing the log function to invert the CDF.
The column labeled MT19973 is used the same 32-bit generator as
<a class="reference internal" href="legacy.html#numpy.random.RandomState" title="numpy.random.RandomState"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RandomState</span></code></a> but produces random values using
<a class="reference internal" href="generator.html#numpy.random.Generator" title="numpy.random.Generator"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Generator</span></code></a>.</p>
<table class="colwidths-given docutils align-default">
<colgroup>
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"></th>
<th class="head"><p>MT19937</p></th>
<th class="head"><p>PCG64</p></th>
<th class="head"><p>Philox</p></th>
<th class="head"><p>SFC64</p></th>
<th class="head"><p>RandomState</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>32-bit Unsigned Ints</p></td>
<td><p>3.2</p></td>
<td><p>2.7</p></td>
<td><p>4.9</p></td>
<td><p>2.7</p></td>
<td><p>3.2</p></td>
</tr>
<tr class="row-odd"><td><p>64-bit Unsigned Ints</p></td>
<td><p>5.6</p></td>
<td><p>3.7</p></td>
<td><p>6.3</p></td>
<td><p>2.9</p></td>
<td><p>5.7</p></td>
</tr>
<tr class="row-even"><td><p>Uniforms</p></td>
<td><p>7.3</p></td>
<td><p>4.1</p></td>
<td><p>8.1</p></td>
<td><p>3.1</p></td>
<td><p>7.3</p></td>
</tr>
<tr class="row-odd"><td><p>Normals</p></td>
<td><p>13.1</p></td>
<td><p>10.2</p></td>
<td><p>13.5</p></td>
<td><p>7.8</p></td>
<td><p>34.6</p></td>
</tr>
<tr class="row-even"><td><p>Exponentials</p></td>
<td><p>7.9</p></td>
<td><p>5.4</p></td>
<td><p>8.5</p></td>
<td><p>4.1</p></td>
<td><p>40.3</p></td>
</tr>
<tr class="row-odd"><td><p>Gammas</p></td>
<td><p>34.8</p></td>
<td><p>28.0</p></td>
<td><p>34.7</p></td>
<td><p>25.1</p></td>
<td><p>58.1</p></td>
</tr>
<tr class="row-even"><td><p>Binomials</p></td>
<td><p>25.0</p></td>
<td><p>21.4</p></td>
<td><p>26.1</p></td>
<td><p>19.5</p></td>
<td><p>25.2</p></td>
</tr>
<tr class="row-odd"><td><p>Laplaces</p></td>
<td><p>45.1</p></td>
<td><p>40.7</p></td>
<td><p>45.5</p></td>
<td><p>38.1</p></td>
<td><p>45.6</p></td>
</tr>
<tr class="row-even"><td><p>Poissons</p></td>
<td><p>67.6</p></td>
<td><p>52.4</p></td>
<td><p>69.2</p></td>
<td><p>46.4</p></td>
<td><p>78.1</p></td>
</tr>
</tbody>
</table>
<p>The next table presents the performance in percentage relative to values
generated by the legacy generator, <code class="docutils literal notranslate"><span class="pre">RandomState(MT19937())</span></code>. The overall
performance was computed using a geometric mean.</p>
<table class="colwidths-given docutils align-default">
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"></th>
<th class="head"><p>MT19937</p></th>
<th class="head"><p>PCG64</p></th>
<th class="head"><p>Philox</p></th>
<th class="head"><p>SFC64</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>32-bit Unsigned Ints</p></td>
<td><p>101</p></td>
<td><p>121</p></td>
<td><p>67</p></td>
<td><p>121</p></td>
</tr>
<tr class="row-odd"><td><p>64-bit Unsigned Ints</p></td>
<td><p>102</p></td>
<td><p>156</p></td>
<td><p>91</p></td>
<td><p>199</p></td>
</tr>
<tr class="row-even"><td><p>Uniforms</p></td>
<td><p>100</p></td>
<td><p>179</p></td>
<td><p>90</p></td>
<td><p>235</p></td>
</tr>
<tr class="row-odd"><td><p>Normals</p></td>
<td><p>263</p></td>
<td><p>338</p></td>
<td><p>257</p></td>
<td><p>443</p></td>
</tr>
<tr class="row-even"><td><p>Exponentials</p></td>
<td><p>507</p></td>
<td><p>752</p></td>
<td><p>474</p></td>
<td><p>985</p></td>
</tr>
<tr class="row-odd"><td><p>Gammas</p></td>
<td><p>167</p></td>
<td><p>207</p></td>
<td><p>167</p></td>
<td><p>231</p></td>
</tr>
<tr class="row-even"><td><p>Binomials</p></td>
<td><p>101</p></td>
<td><p>118</p></td>
<td><p>96</p></td>
<td><p>129</p></td>
</tr>
<tr class="row-odd"><td><p>Laplaces</p></td>
<td><p>101</p></td>
<td><p>112</p></td>
<td><p>100</p></td>
<td><p>120</p></td>
</tr>
<tr class="row-even"><td><p>Poissons</p></td>
<td><p>116</p></td>
<td><p>149</p></td>
<td><p>113</p></td>
<td><p>168</p></td>
</tr>
<tr class="row-odd"><td><p>Overall</p></td>
<td><p>144</p></td>
<td><p>192</p></td>
<td><p>132</p></td>
<td><p>225</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>All timings were taken using Linux on a i5-3570 processor.</p>
</div>
</div>
<div class="section" id="performance-on-different-operating-systems">
<h2>Performance on different Operating Systems<a class="headerlink" href="#performance-on-different-operating-systems" title="Permalink to this headline">¶</a></h2>
<p>Performance differs across platforms due to compiler and hardware availability
(e.g., register width) differences. The default bit generator has been chosen
to perform well on 64-bit platforms.  Performance on 32-bit operating systems
is very different.</p>
<p>The values reported are normalized relative to the speed of MT19937 in
each table. A value of 100 indicates that the performance matches the MT19937.
Higher values indicate improved performance. These values cannot be compared
across tables.</p>
<div class="section" id="bit-linux">
<h3>64-bit Linux<a class="headerlink" href="#bit-linux" title="Permalink to this headline">¶</a></h3>
<table class="docutils align-default">
<colgroup>
<col style="width: 38%" />
<col style="width: 18%" />
<col style="width: 14%" />
<col style="width: 16%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Distribution</p></th>
<th class="head"><p>MT19937</p></th>
<th class="head"><p>PCG64</p></th>
<th class="head"><p>Philox</p></th>
<th class="head"><p>SFC64</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>32-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>119.8</p></td>
<td><p>67.7</p></td>
<td><p>120.2</p></td>
</tr>
<tr class="row-odd"><td><p>64-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>152.9</p></td>
<td><p>90.8</p></td>
<td><p>213.3</p></td>
</tr>
<tr class="row-even"><td><p>Uniforms</p></td>
<td><p>100</p></td>
<td><p>179.0</p></td>
<td><p>87.0</p></td>
<td><p>232.0</p></td>
</tr>
<tr class="row-odd"><td><p>Normals</p></td>
<td><p>100</p></td>
<td><p>128.5</p></td>
<td><p>99.2</p></td>
<td><p>167.8</p></td>
</tr>
<tr class="row-even"><td><p>Exponentials</p></td>
<td><p>100</p></td>
<td><p>148.3</p></td>
<td><p>93.0</p></td>
<td><p>189.3</p></td>
</tr>
<tr class="row-odd"><td><p><strong>Overall</strong></p></td>
<td><p>100</p></td>
<td><p>144.3</p></td>
<td><p>86.8</p></td>
<td><p>180.0</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="bit-windows">
<h3>64-bit Windows<a class="headerlink" href="#bit-windows" title="Permalink to this headline">¶</a></h3>
<p>The relative performance on 64-bit Linux and 64-bit Windows is broadly similar.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 38%" />
<col style="width: 18%" />
<col style="width: 14%" />
<col style="width: 16%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Distribution</p></th>
<th class="head"><p>MT19937</p></th>
<th class="head"><p>PCG64</p></th>
<th class="head"><p>Philox</p></th>
<th class="head"><p>SFC64</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>32-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>129.1</p></td>
<td><p>35.0</p></td>
<td><p>135.0</p></td>
</tr>
<tr class="row-odd"><td><p>64-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>146.9</p></td>
<td><p>35.7</p></td>
<td><p>176.5</p></td>
</tr>
<tr class="row-even"><td><p>Uniforms</p></td>
<td><p>100</p></td>
<td><p>165.0</p></td>
<td><p>37.0</p></td>
<td><p>192.0</p></td>
</tr>
<tr class="row-odd"><td><p>Normals</p></td>
<td><p>100</p></td>
<td><p>128.5</p></td>
<td><p>48.5</p></td>
<td><p>158.0</p></td>
</tr>
<tr class="row-even"><td><p>Exponentials</p></td>
<td><p>100</p></td>
<td><p>151.6</p></td>
<td><p>39.0</p></td>
<td><p>172.8</p></td>
</tr>
<tr class="row-odd"><td><p><strong>Overall</strong></p></td>
<td><p>100</p></td>
<td><p>143.6</p></td>
<td><p>38.7</p></td>
<td><p>165.7</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id1">
<h3>32-bit Windows<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>The performance of 64-bit generators on 32-bit Windows is much lower than on 64-bit
operating systems due to register width. MT19937, the generator that has been
in NumPy since 2005, operates on 32-bit integers.</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 38%" />
<col style="width: 18%" />
<col style="width: 14%" />
<col style="width: 16%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Distribution</p></th>
<th class="head"><p>MT19937</p></th>
<th class="head"><p>PCG64</p></th>
<th class="head"><p>Philox</p></th>
<th class="head"><p>SFC64</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>32-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>30.5</p></td>
<td><p>21.1</p></td>
<td><p>77.9</p></td>
</tr>
<tr class="row-odd"><td><p>64-bit Unsigned Int</p></td>
<td><p>100</p></td>
<td><p>26.3</p></td>
<td><p>19.2</p></td>
<td><p>97.0</p></td>
</tr>
<tr class="row-even"><td><p>Uniforms</p></td>
<td><p>100</p></td>
<td><p>28.0</p></td>
<td><p>23.0</p></td>
<td><p>106.0</p></td>
</tr>
<tr class="row-odd"><td><p>Normals</p></td>
<td><p>100</p></td>
<td><p>40.1</p></td>
<td><p>31.3</p></td>
<td><p>112.6</p></td>
</tr>
<tr class="row-even"><td><p>Exponentials</p></td>
<td><p>100</p></td>
<td><p>33.7</p></td>
<td><p>26.3</p></td>
<td><p>109.8</p></td>
</tr>
<tr class="row-odd"><td><p><strong>Overall</strong></p></td>
<td><p>100</p></td>
<td><p>31.4</p></td>
<td><p>23.8</p></td>
<td><p>99.8</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Linux timings used Ubuntu 18.04 and GCC 7.4.  Windows timings were made on
Windows 10 using Microsoft C/C++ Optimizing Compiler Version 19 (Visual
Studio 2015). All timings were produced on a i5-3570 processor.</p>
</div>
</div>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>